﻿@{
    ViewBag.Title = "Link";
    var currentUser = Session[NCLCustomerManagement.Common.Constant.Constant.CURRENT_USER]
                       as NCLCustomerManagement.UI.Models.User.AuthenticatedUser;
    var username = currentUser.Username;
    var isAdmin = currentUser.IsAdmin;                       
}


@Html.Partial("_CustomerInput")
<div class="btn-toolbar">
    <div class="bt-n-group" style="float: right;">
        <button id="btnSave" class="btn btn-primary" onclick="save();"><span class="glyphicon glyphicon-save" title="Lưu">Lưu</span></button>
        <button id="btnCancel" class="btn btn-default" onclick="cancel();"><span class="glyphicon glyphicon-log-out" title="Hủy">Hủy</span></button>
    </div>
</div>

<script>
    function save() {
        var d = getCustomerModel();
        if (d.Id == '')
            d.Id = -1;

        validate(d, function () {
            submitNewOrEdit(d, true, function (data) {
                if (data.Success) {
                    showMessage("#alertbox", "Đã thêm khách hàng");
                    $("#list").jqGrid('setGridParam', { datatype: 'json' });
                    $('#list').trigger('reloadGrid');
                }
                else {
                    showMessage("#alertbox", "Không thể thêm khách hàng");
                }
                $('#editWindow').modal('hide');
            });
        });

    }

    $(document).ready(function () {
        $("#btnRemoveCate").click(function () {
            var items = getSelectedItems($("#BoughtCates"));
            $(items).each(function () {
                if (!containItem($("#FoundCategories"), $(this).val())) {
                    $("#FoundCategories").append($(this));
                }
                else {
                    $("#BoughtCates option[value=" + $(this).val() + "]").remove();
                }
            });

            function checkProductOfCustomerExist(id) {

            }
        });
    });
   
</script>
